package com.hanock.sm.fork2d;

public class ScaleRepeatTransform extends Transform{

	
	private float amplitude;
	private float period;
	private int timeFrom;
	private int timeTo;
	
	
	public ScaleRepeatTransform(float amplitude, float period, int timeFrom, int timeTo) {
		
		this.amplitude = amplitude;
		this.period = period;
		this.timeFrom = timeFrom;
		this.timeTo = timeTo;
	}
	
	@Override
	public void progress(Node node, int time) {
		super.progress(node, time);
		
		if (period <= 0)
			return;
		
		int act = getActionTime() - timeFrom;
		int interval = timeTo - timeFrom;
		
		if (act < 0 || act > interval)
			return;
		
		float s = 1 + amplitude*(float)Math.sin(2*Math.PI*act/period);
		
		node.setScale(s, s);
	}
	
	@Override
	public boolean isFinished() {
		return getActionTime() > timeTo;
	}
}







